SET(PROJ_NAME endless)

include_directories(${PROJECT_SOURCE_DIR}/base/include)
include_directories(${PROJECT_SOURCE_DIR}/common/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/system_server/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/media/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/event/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/stream_server/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/web_server/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/cloud_model/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/storage/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/record/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/upgrade/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/restful/include)
include_directories(${PROJECT_SOURCE_DIR}/foundation/protocol/include)

include_directories(${PROJECT_SOURCE_DIR}/hal/init/include)

file(GLOB CPP_SOURCE_FILE "*.cpp")

set(ALL_SOURCES ${CPP_SOURCE_FILE} ${C_SOURCE_FILE})

link_libraries(${EL_ALL_LIBS})

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "m64x86")
    message("Building for m64x86 platform")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
    message("Building for aarch64 platform")
endif()

add_executable(${PROJ_NAME} ${ALL_SOURCES})

if(CMAKE_BUILD_TYPE STREQUAL "release")
    add_custom_command(TARGET ${PROJ_NAME} POST_BUILD
        COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${PROJ_NAME}>
        COMMENT "Stripping ${PROJ_NAME} executable"
    )
endif()

# 创建输出目录
set(OUTPUT_BIN_DIR ${CMAKE_SOURCE_DIR}/out/bin)
file(MAKE_DIRECTORY ${OUTPUT_BIN_DIR})

# 复制可执行文件到out/bin目录
add_custom_command(TARGET ${PROJ_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJ_NAME}> ${OUTPUT_BIN_DIR}/${PROJ_NAME}
    COMMENT "Copying ${PROJ_NAME} to ${OUTPUT_BIN_DIR}"
)
